
import datetime
import time
import pandas
import csv, sqlite3
import sqlalchemy
from pandas.core.frame import DataFrame

def get_timestamp(datestr):
    # print datestr
    d = datetime.datetime.strptime(datestr, '%Y-%m-%d %H:%M:%S')
    end = time.clock()

    return int(time.mktime(d.timetuple()))

contents = []
with open('./data/EURUSD_15 Mins_Ask_2003.01.23_2018.01.29.csv') as f:
	for line in f:
		content = line.split(',')
		timestr = content[0]
		timestamp = get_timestamp(timestr)
		o = float(content[1])
		h = float(content[2])
		l = float(content[3])
		c = float(content[4])
		v = float(content[5])
		contents.append([timestr,o,h,l,c,v,timestamp])


df=DataFrame(contents)#这时候是以行为标准写入的
conn= sqlite3.connect("./db/fxdata.db")
df.rename(columns={0:'datetime',1:'open',2:'high',3:'low',4:'close',5:'vol',6:'timestamp'},inplace=True)
df.to_sql('eurusd_15', conn, if_exists='append', index=False)
print('ok')